package com.cz.basetool.ui_work.util.txt;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by 陈章 on 2017/12/16.
 */
public class CZ_TextUtil {
    public final static String divider = "###############################################################";
    public final static String CR = "\n";
    public static boolean is_null_or_empty(String str){
        return str == null || str.isEmpty() || str.equals("null");
    }

    public static boolean is_null_or_emptyAll( String[] strs){
        boolean result =  true;
        for (String item :strs){
            if(!is_null_or_empty(item)){
                result = false;
                break;
            }
        }
        return result;
    }

    public static boolean isRightTxtAll( String[] strs){
        boolean result =  true;
        for (String item :strs){
            if(is_null_or_empty(item)){
                result = false;
                break;
            }
        }
        return result;
    }



    public static String get2PointNumber(double num){
        return String.format("%.2f",num);
    }

    /**
     * 删除字符中所有的回车、空格、制表符
     * https://www.cnblogs.com/love540376/p/5807352.html
     * @param str
     * @return
     */
    public static String replaceBlank(String str) {
        String dest = "";
        if (str!=null) {
            Pattern p = Pattern.compile("\\s*|\t|\r|\n");
            Matcher m = p.matcher(str);
            dest = m.replaceAll("");
        }
        return dest;
    }


    public static boolean isNumeric(String str){
        for (int i = 0; i < str.length(); i++){
            System.out.println(str.charAt(i));
            if (!Character.isDigit(str.charAt(i))){
                return false;
            }
        }
        return true;
    }

    /**
     * 是否有小写字母
     * @param txt
     * @return
     */
    public static boolean hasLowerLitter(String txt){
        char[] chars = txt.toCharArray();
        for (char item :chars){
            if(item >= 'a' && item <= 'z'){
                return true;
            }
        }
        return false;
    }

    //创建https协议头
    public static String crateHttpsHead(String ip,String port){
        return "https://" + ip + (port.isEmpty() ? "" : ":") + port;
    }
}